class Washer:
    # __xx__()的函数叫魔法方法，指特殊方法
    def __init__(self):  # 构造方法
        self.height = 800
        print('构造方法')

    def wash(self):  # self指调用该方法的对象
        print('洗衣服')
        print(self)
        # print(self.width)  # 类里边获取对象属性
        print(self.height)


washer = Washer()
print(washer)
washer.wash()

washer1 = Washer()
print(washer1)
washer1.wash()

# 类外边添加对象属性
washer.width = 100
print(washer.width)


class Student:

    def __init__(self, name, age):
        self.name = name
        self.age = age
        print('%s的年龄为%d' % (name, age))

    def __str__(self):  # 默认打印对象的地址值
        return 'str'

    def __del__(self):  # 当删除对象时，python解释器会调用__del__(self)
        print(f'{self}对象被删除')


student = Student('小明', 18)
print(student)
del student


class Dog:
    tooth = 10  # 类属性.可以使用类名调用,共有的,相当于java静态也可以对象调用 修改时相当于成员变量


dog = Dog()
dog2 = Dog()
print(Dog.tooth)
print(dog.tooth)  # 先找对象属性,没有就用类属性,再没有就报错
dog2.tooth = 11  # 先找对象属性,没有就相当于定义了
print(dog2.tooth)
print(dog.tooth)
print(Dog.tooth)

Dog.tooth = 12
print(dog2.tooth)
print(dog.tooth)
print(Dog.tooth)


class Cat:
    __tooth = 100

    # 定义类方法
    @classmethod
    def get_tooth(cls):
        return cls.__tooth

    # 定义静态方法. 对象调用和类调用都行
    @staticmethod
    def info():
        print('静态方法')

    def haha(self):
        return 'haha'


cat = Cat()
print(cat.get_tooth())
print(Cat.get_tooth())
# print(Cat.haha())  # 会报错.因为这是对象方法
print(cat.haha())
Cat.info()
cat.info()
